# 静态内部类方式实现单例：利用Python的模块特性模拟
class SingletonStaticInner:
    class __SingletonStaticInner:
        def __init__(self):
            self.value = None

        def __str__(self):
            return f"Singleton instance (value: {self.value})"

    # 静态内部类实例
    _instance = None

    def __new__(cls):
        if not SingletonStaticInner._instance:
            SingletonStaticInner._instance = SingletonStaticInner.__SingletonStaticInner()
        return SingletonStaticInner._instance

    def __getattr__(self, name):
        return getattr(self._instance, name)

    def __setattr__(self, name, value):
        setattr(self._instance, name, value)


# 测试
if __name__ == "__main__":
    s1 = SingletonStaticInner()
    s2 = SingletonStaticInner()
    s1.value = "test"
    print(f"静态内部类 - s1和s2是否为同一实例: {s1 is s2}")  # 输出 True
    print(f"s1.value = {s1.value}, s2.value = {s2.value}")  # 输出相同值